package DynamicProgramming;

import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Scanner;

class Solver1013
{	int n,k;
	BigInteger[] Dyn0,DynNorm;

	public void Input()
	{	Scanner in=new Scanner(System.in);
		n=in.nextInt();k=in.nextInt();
		
		Dyn0=new BigInteger[n+1];
		DynNorm=new BigInteger[n+1];
	}
	public void Solve()
	{	BigInteger tp=new BigInteger((k-1)+"");
		Dyn0[1]=BigInteger.ZERO;
		DynNorm[1]=tp;
		for (int i=2;i<=n;i++)
		{	Dyn0[i]=DynNorm[i-1];
			DynNorm[i]=tp.multiply((Dyn0[i-1].add(DynNorm[i-1])));
		}
	}
	public void Output()
	{	PrintWriter out=new PrintWriter(System.out);
		out.println(Dyn0[n].add(DynNorm[n]));
		out.flush();
	}
	public void main()
	{	Input();
		Solve();
		Output();
	}
}
public class P1013
{	public static void main(String[] args)
	{	Solver1013 solver=new Solver1013();
		solver.main();
	}
}
